<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" id="reset" />
    <button id="btn">登入</button>

    <script>
      //1、点击button按钮 ->2、获取input的值  -->3、验证输入是否正确
      //结果不可用，给提示，然后返回
      // 结果正确  1、按钮禁用 -->修改文本，倒计时 --> 倒计时结束后，恢复按钮，修改文本，重新获取时间
      var resetName = document.getElementById('reset');
      var btnEle = document.getElementById('btn');
      var time = 5;
      var setTime;
      btnEle.addEventListener('click', function () {
        console.log('hhh');
        var phone = resetName.value;
        var reg = /^1\d{10}$/;
        // if (reg.test(phone)) {
        btnEle.disabled = true;

        setTime = setInterval(function () {
          time--;
          btnEle.innerText = time + '倒计时';
          if (time === 0) {
          console.log('if执行了');
          clearInterval(setTime);
          btnEle.disabled = false;
          btnEle.innerText = '登入';
          time = 5;
        }
        }, 1000);

      

        // } else {
        //   alert('请正确输入手机号码');
        // }
      });
    </script>
  </body>
</html>
